<?php

class AfterSalesController extends BaseController
{
	
	public function actionAdmin()
	{
		$model = new Block();//碎片表
		$model->zm_id = Company::model()->getCmpUserId();//商家ID
		$model->zbl_type = '1';//类型为HTML
		$model->zbl_pos = 'service';//售后模板
		$this->render('salesterm',array(
			'model'=>$model,
		));
	}

	/*
	 * 新建
	 * */
	public function actionCreate()
	{
		$model = new Block();//碎片表
		$model->attributes = $_POST['Block'];
		if($model->save()){
			//成功跳转
			$this->redirect(Yii::app()->request->urlReferrer);
		}
	}
	
	/*
	 * 更新
	 * */
	public function actionUpdate($id)
	{
		$model=$this->loadModel($id);

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['Block']))
		{
			$model->attributes=$_POST['Block'];
			if($model->save()){
				//成功跳转
				$this->redirect(array('admin'));
			}
		}

		$this->render('update',array(
			'model'=>$model,
		));
	}
	
	/*
	 * 删除
	 * */
	public function actionDelete()
	{
		$ids = isset($_GET['id'])?$_GET['id']:join(',',$_POST['ids']);
		
		$criteria=new CDbCriteria;
		$criteria->condition = "zbl_id in ($ids)";
		if(Block::model()->deleteAll($criteria)){
			//成功跳转
			$this->redirect(Yii::app()->request->urlReferrer);
		}
	}
	
	/*
	 * 加载模型
	 * */
	public function loadModel($id)
	{
		$model=Block::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}